var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css'),
    minifyImg = require('gulp-imagemin'),
    rev = require('gulp-rev'),
    revCollector = require('gulp-rev-collector'),
    minifyHtml = require('gulp-minify-html'),
    rename = require('gulp-rename'),
    replace = require('gulp-replace'),
    cache = require('gulp-cache'),

    P = require('./config.js').pathes

gulp.task('uglifyJs', function () {
    return gulp.src(P.dev + '/js/*.js', {
            base: P.dev
        })
        .pipe(uglify())
        .pipe(gulp.dest(P.build))
})

gulp.task('minifyCss', function () {
    return gulp.src(P.dev + '/css/*.css', {
            base: P.dev
        })
        // .pipe(replace('../', '/assets/'))
        .pipe(minifyCss())
        .pipe(gulp.dest(P.build))
})

gulp.task('minifyHtml', function () {
    return gulp.src(P.dev + '/*.html', {
            base: P.dev
        })
        .pipe(replace('../', '/'))
        .pipe(minifyHtml({
             empty: true,
             spare: true
         }))
        .pipe(gulp.dest(P.build))

})

gulp.task('minifyImg', function () {
    return gulp.src(P.dev + '/images/*.{png,jpg,gif}')
        // .pipe(cache(minifyImg({
        //     progressive: false
        // })))
        .pipe(gulp.dest(P.build + '/images'))
})

module.exports = {
    start: function () {
        gulp.task('build', ['uglifyJs', 'minifyCss', 'minifyHtml', 'minifyImg'])
    }
}